package com.ruoyi.web.controller.system;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysSong;
import com.ruoyi.system.service.ISysSongService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 歌曲信息Controller
 * 
 * @author Johnson
 * @date 2025-04-30
 */
@RestController
@RequestMapping("/system/song")
@RequiredArgsConstructor
public class SysSongController extends BaseController {

    private final ISysSongService sysSongService;

    /**
     * 查询歌曲信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:song:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSong sysSong) {
        startPage();
        List<SysSong> list = sysSongService.selectSysSongList(sysSong);
        return getDataTable(list);
    }

    /**
     * 导出歌曲信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:song:export')")
    @Log(title = "歌曲信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysSong sysSong) {
        List<SysSong> list = sysSongService.selectSysSongList(sysSong);
        ExcelUtil<SysSong> util = new ExcelUtil<SysSong>(SysSong.class);
        util.exportExcel(response, list, "歌曲信息数据");
    }

    /**
     * 获取歌曲信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:song:query')")
    @GetMapping(value = "/{songId}")
    public AjaxResult getInfo(@PathVariable("songId") Long songId) {
        return success(sysSongService.selectSysSongBySongId(songId));
    }

    /**
     * 新增歌曲信息
     */
    @PreAuthorize("@ss.hasPermi('system:song:add')")
    @Log(title = "歌曲信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSong sysSong) {
        return toAjax(sysSongService.insertSysSong(sysSong));
    }

    /**
     * 修改歌曲信息
     */
    @PreAuthorize("@ss.hasPermi('system:song:edit')")
    @Log(title = "歌曲信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSong sysSong) {
        return toAjax(sysSongService.updateSysSong(sysSong));
    }

    /**
     * 删除歌曲信息
     */
    @PreAuthorize("@ss.hasPermi('system:song:remove')")
    @Log(title = "歌曲信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{songIds}")
    public AjaxResult remove(@PathVariable Long[] songIds) {
        return toAjax(sysSongService.deleteSysSongBySongIds(songIds));
    }
}
